(define (make-account balance password)
  (define (withdraw amount)
    (if (>= balance amount)
        (begin (set! balance (- balance amount))
               balance)
        "Insufficient funds"))
  (define (deposit amount)
    (set! balance (+ balance amount)))
  (define (dispatch pw m)
    (if (eq? pw password)
        (cond ((eq? m 'withdraw) withdraw)
              ((eq? m 'deposit) deposit)
              (else (error "Unknown request -- MAKE-ACCOUNT" m)))
        (lambda (x) "Incorrect password")))
  dispatch)

(define (make-joint acc pw new-pw)
  (let ((withdraw (acc pw 'withdraw))
        (deposit (acc pw 'deposit)))
    (define (dispatch pw m)
      (cond ((not (eq? pw new-pw)) (lambda (x)
                                     "Incorrect Password"))
            ((eq? m 'withdraw) withdraw)
            ((eq? m 'deposit) deposit)
            (else (error "Unknown request -- MAKE-JOINT" m))))
    (if (not (number? (withdraw 0)))
        (error "Incorrect password for jointed account" (list pw))
        dispatch)))

(define peter-acc (make-account 100 'open-sesame))
(define paul-acc (make-joint peter-acc 'open-sesame 'rosebud))

((peter-acc 'open-sesame 'withdraw) 0)
((paul-acc 'open-seasame 'withdraw) 50)
((paul-acc 'rosebud 'withdraw) 50)
((peter-acc 'open-sesame 'withdraw) 0)

(define bob-acc (make-joint peter-acc 'openingsesame 'rosebud))